﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using University.Workshop.Business;

namespace University.Workshop.Presenters.FeesAndFines.Modify
{
    public class PresenterModifyFees
    {
        IModifyFeesView view;
        Model.FeesAndFines feesAndFines = new Model.FeesAndFines();

        public PresenterModifyFees(IModifyFeesView view)
        {
            this.view = view;
        }

        public void LoadFeesAndFines()
        {
            try
            {
                Model.FeesAndFines f = ManagerFeesAndFines.GetCurrentFees();
                this.feesAndFines.id = f.id;
                this.feesAndFines.Charge = f.Charge;
                this.feesAndFines.NewConection = f.NewConection;
                this.feesAndFines.Reconnection = f.Reconnection;
                this.feesAndFines.BaseRate = f.BaseRate;
                this.feesAndFines.NewMember = f.NewMember;
                this.feesAndFines.MonthlyContribution = f.MonthlyContribution;
                this.feesAndFines.NonPayment = f.NonPayment;
                this.feesAndFines.MeterViolation = f.MeterViolation;
                this.feesAndFines.EffectiveDate = f.EffectiveDate;
            }
            catch(Exception e)
            {
                view.ErrorMessage(e.Message);
                view.GoRegisterFees();
            }
        }

        public void LoadViewData()
        {
            LoadFeesAndFines();
            view.Charge = feesAndFines.Charge;
            view.NewConnection = feesAndFines.NewConection;
            view.Reconnection = feesAndFines.Reconnection;
            view.BaseRate = feesAndFines.BaseRate;
            view.NewMember = feesAndFines.NewMember;
            view.MonthlyContribution = feesAndFines.MonthlyContribution;
            view.NonPayment = feesAndFines.NonPayment;
            view.MeterViolation = feesAndFines.MeterViolation;
            view.EffectiveDate = feesAndFines.EffectiveDate;
        }

        public void ModifyFees()
        {
            try
            {
                feesAndFines.Charge = view.Charge;
                feesAndFines.NewConection = view.NewConnection;
                feesAndFines.Reconnection = view.Reconnection;
                feesAndFines.BaseRate = view.BaseRate;
                feesAndFines.NewMember = view.NewMember;
                feesAndFines.MonthlyContribution = view.MonthlyContribution;
                feesAndFines.NonPayment = view.NonPayment;
                feesAndFines.MeterViolation = view.MeterViolation;
                feesAndFines.EffectiveDate = view.EffectiveDate;

                ManagerFeesAndFines.VerifyDataFees(feesAndFines);
                ManagerFeesAndFines.ModifyFees(feesAndFines);
                view.SystemMessage("Las Tarifas Fueron Modificadas Exitosamente.!!!!");
                view.ReturnSearchFees();
            }
            catch (Exception ex)
            {
                view.ErrorMessage(ex.Message);
            }
        }
    }
}
